<?php
namespace App\Exception\Handler;

use App\Exception\OverfrequencyException;
use Swoft\Error\Annotation\Mapping\ExceptionHandler;
use Swoft\Http\Message\ContentType;
use Swoft\Http\Message\Response;
use Swoft\Http\Server\Exception\Handler\AbstractHttpErrorHandler;
use Throwable;

/**
 * Class OverfrequencyExceptionHandler
 * @package App\Exception\Handler
 * @ExceptionHandler(OverfrequencyException::class)
 */
class OverfrequencyExceptionHandler extends AbstractHttpErrorHandler
{

    /**
     * @inheritDoc
     */
    public function handle(Throwable $e, Response $response): Response
    {
        $data = [
            'status'=>403,
            'error_code'=>403,
            'error_user_title'=>'提示',
            'error_user_msg'=>'请勿重复提交!',
            'message'=>"别点了，忙不过来了",
        ];

        return $response->withHeader('Access-Control-Allow-Origin', '*')
            ->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
            ->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS')
            ->withContentType(ContentType::JSON)->withData($data);
    }
}
